########################################################################
#  Wiizard - A Wii games manager
#  Copyright (C) 2023  CYBERDEViL
#
#  This file is part of Wiizard.
#
#  Wiizard is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Wiizard is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
########################################################################


class GameImageSettings:
  LANGUAGES = [  # TODO for now only based on available from gametdb
    "EN",
    "US",
    "JA",
    "FR",
    "DE",
    "ES",
    "IT",
    "NL",
    "PT",
    "RU",
    "KO",
    "ZHCN",
    "ZHTW"
  ]

  PreferredLang   = "US"
  FallbackLang    = None
  AnyFallback     = True

  @staticmethod
  def setPreferredLang(lang):
    """ lang must be a valid language from GameImageSettings.LANGUAGES """
    GameImageSettings.PreferredLang = lang

  @staticmethod
  def setFallbackLang(lang):
    """ lang may be None """
    GameImageSettings.FallbackLang = lang

  @staticmethod
  def setAnyFallbackEnabled(state=True):
    GameImageSettings.AnyFallback = state

  @staticmethod
  def getLanguages():
    if GameImageSettings.AnyFallback is True and GameImageSettings.FallbackLang is not None:
      return (GameImageSettings.PreferredLang, GameImageSettings.FallbackLang, "*")

    if GameImageSettings.AnyFallback is True:
      return (GameImageSettings.PreferredLang, "*")

    return (GameImageSettings.PreferredLang)

  @staticmethod
  def serialize():
    return {
      "preferred"  : GameImageSettings.PreferredLang,
      "fallback"   : GameImageSettings.FallbackLang,
      "anyFallback": GameImageSettings.AnyFallback
    }

  @staticmethod
  def deserialize(data):
    GameImageSettings.PreferredLang = data.get("preferred"  , GameImageSettings.PreferredLang)
    GameImageSettings.FallbackLang  = data.get("fallback"   , GameImageSettings.FallbackLang)
    GameImageSettings.AnyFallback   = data.get("anyFallback", GameImageSettings.AnyFallback)
